﻿using MesErreurs;
using Metier;
using Persistance;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Utilitaires;

namespace Gestion_commerciale
{
    public partial class FModif_Cde : Form
    {
        Commande commande;
        public FModif_Cde(String numCommande)
        {
            InitializeComponent();
            bNumArt.Text = numCommande;
            commande = new Commande();
            commande.RechercheUneCommande(numCommande);
            bNumClient.Text = commande.NoClient.NoClient.ToString();
            bNumVend.Text = commande.NoVendeur.NoVendeur.ToString();
            bDate.Value=Convert.ToDateTime(commande.DateCommande);
            if (commande.Facture.ToString() == "F") bNon.Checked = true;
            else bOui.Checked = true;    
            List<String> mesNumeros;
            try
            {
                // Lecture classique
                Clientel unClient = new Clientel();
                mesNumeros = unClient.LectureNoClient();
                foreach (String item in mesNumeros)
                {
                    bNumClient.Items.Add(item);
                }
            }
            catch (MonException exception)
            {
                MessageBox.Show(exception.MessageApplication(), exception.Message);
            }


            try
            {
                // Lecture classique
                Vendeur unVendeur = new Vendeur();
                mesNumeros = unVendeur.LectureNoVendeur();
                foreach (String item in mesNumeros)
                {
                    bNumVend.Items.Add(item);
                }
            }
            catch (MonException exception)
            {
                MessageBox.Show(exception.MessageApplication(), exception.Message);
            }
        }

        private void bModifier_Click(object sender, EventArgs e)
        {
            if (bOui.Checked == true) commande.Facture = "T";
            else commande.Facture = "F";
            commande.DateCommande = Fonctions.DateToString(bDate.Value);
            commande.NoClient.NoClient = bNumClient.Text;
            commande.NoVendeur.NoVendeur = bNumVend.Text;
            commande.modifierCommande();
            Close();
        }
    }
}
